package com.house.mapper;

import com.house.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("INSERT INTO rental_order (house_id, tenant_id, landlord_id, appointment_date, status, price) " +
            "VALUES (#{houseId}, #{tenantId}, #{landlordId}, #{appointmentDate}, #{status}, #{price})")
    void insertOrder(Order order);

    @Update("UPDATE rental_order SET status = #{status} WHERE id = #{orderId} AND landlord_id = #{landlordId}")
    void updateOrderStatus(@Param("orderId") Long orderId, @Param("landlordId") Long landlordId, @Param("status") String status);

    @Update("UPDATE rental_order SET status = 'PAID' WHERE id = #{orderId} AND tenant_id = #{tenantId}")
    void payOrder(@Param("orderId") Long orderId, @Param("tenantId") Long tenantId);

    @Select("SELECT * FROM rental_order WHERE tenant_id = #{tenantId}")
    List<Order> findOrdersByTenantId(@Param("tenantId") Long tenantId);

    @Select("SELECT * FROM rental_order WHERE landlord_id = #{landlordId}")
    List<Order> findOrdersByLandlordId(@Param("landlordId") Long landlordId);
}

